package com.situ.crm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.crm.VO.LayUISelectMVO;
import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.Permission;
import com.situ.crm.entity.SaleChance;
import com.situ.crm.mapper.PermissionMapper;
import com.situ.crm.mapper.SaleChanceMapper;
import com.situ.crm.service.IPermissionService;
import com.situ.crm.service.ISaleChanceService;

@Service
public class SaleChanceServiceImpl implements ISaleChanceService {

	@Autowired
	private SaleChanceMapper saleChanceMapper;

	@Override
	public ServerResponse pageList(Integer page, Integer limit) {
		// pageListHelper插件进行分页
		PageHelper.startPage(page, limit);
		// 执行查询
		List<SaleChance> list = saleChanceMapper.pageList();
		// pageinfo对结果进行包装
		PageInfo pageInfo = new PageInfo<>(list);
		Integer count = (int) pageInfo.getTotal();
		return ServerResponse.createSuccess("查询成功", count, list);
	}

	@Override
	public ServerResponse insert(SaleChance saleChance) {
		Integer count = saleChanceMapper.insertSelective(saleChance);
		if (count == 1) {
			return ServerResponse.createSuccess("添加成功");
		}else{
			return ServerResponse.createSuccess("添加失败");
		} 
	}

	@Override
	public SaleChance selectById(Integer id) {
		SaleChance saleChance = saleChanceMapper.selectByPrimaryKey(id);
		
		return saleChance;
	}
}
